package com.ruoyi.tuanzhang.mapper.impl;

import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.tuanzhang.domain.DarenHomeFansDataDo;
import com.ruoyi.tuanzhang.domain.excelDto.DarenHomeFansDataExcelDto;
import com.ruoyi.tuanzhang.mapper.DarenBaseMapper;
import com.ruoyi.tuanzhang.mapper.DarenHomeFansDataMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * 达人base
 * */
@Component
public class DarenHomeFansDataMapperImpl {

    @Autowired
    private static DarenBaseMapper darenBaseMapper;
    @Autowired
    private static DarenHomeFansDataMapper darenHomeFansDataMapper;

    private DarenHomeFansDataMapperImpl (DarenBaseMapper baseMapper, DarenHomeFansDataMapper fansDataMapper) {
        darenBaseMapper = baseMapper;
        darenHomeFansDataMapper = fansDataMapper;
    }

    /**
     * 根据传进来的uid查找粉丝信息
     * @param uids 用户id
     * @param map  k:用户id  v:用户昵称
     * */
    public static List<DarenHomeFansDataExcelDto> getSingleExcel(List<String> uids, Map<String, String> map) {
        if (Objects.isNull(uids) || uids.isEmpty()) {
            return new ArrayList<>();
        }
        QueryWrapper<DarenHomeFansDataDo> wrapper = new QueryWrapper<>();
        wrapper.in("uid", uids);
        List<DarenHomeFansDataDo> darenHomeFansDataDos = darenHomeFansDataMapper.selectList(wrapper);
        List<DarenHomeFansDataExcelDto> list = JSONArray.parseArray(JSONArray.toJSONString(darenHomeFansDataDos), DarenHomeFansDataExcelDto.class);
        if (Objects.nonNull(list) && !list.isEmpty()) {
            for (DarenHomeFansDataExcelDto darenHomeFansDataExcelDto : list) {
                darenHomeFansDataExcelDto.setNickname(map.get(darenHomeFansDataExcelDto.getUid()));
            }
        } else {
            return new ArrayList<>();
        }
        return list;
    }


}
